﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using medicine.DAL;
using medicine.BaseComponents.Groups;
using System.Data.Common;

namespace medicine
{
    
    public class GroupInfo
    {
        //public List<int> SelectedIds = new List<int>();
        public string DBDisplayField = "";
        public string DBValueField = "";
        public string DBTableName = "";
        public string DBValueFieldType = "";
        public string Text = "";
        public int Order = 0;
        public bool isSelectedRow = false;
        public int SelectedRowOrder = 0;
        public List<string> Selected = new List<string>();
        public bool isFiltered
        {
            get { return Selected.Count > 0; }
        }
        public bool isColumn = false;

        [System.Xml.Serialization.XmlIgnore]
        public IGroupDataSource CustomDataSource=null;

        public void Reset()
        {
            isSelectedRow = false;
            SelectedRowOrder = 0;
            Selected = new List<string>();
        }

        public void Copy(GroupInfo src)
        {
            isSelectedRow = src.isSelectedRow;
            SelectedRowOrder = src.SelectedRowOrder;
            Selected = src.Selected;
        }

        public DbDataReader GetDataReader(bool isQuery,string Conditions)
        {
            if (this.CustomDataSource != null)
            {
                return CustomDataSource.GetDataSource();
            }
            else
            {
                string SSQL ="";
                if (!isQuery)
                    SSQL = MedicineDBStructure.GetSelectStatment(this.DBTableName, this.DBValueField, this.DBDisplayField, "", "");
                else
                    if (!string.IsNullOrWhiteSpace( Conditions))
                        SSQL = MedicineDBStructure.GetQueryStatment(this.DBTableName, this.DBValueField, this.DBDisplayField, Conditions);
                    else
                        SSQL = MedicineDBStructure.GetSelectStatment(this.DBTableName, this.DBValueField, this.DBDisplayField, "", "");
                return OleDbUtilities.ExecuteDataReader(SSQL);
            }
        }

    }
}
